<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CalendarItem
 *
 * @author virtual
 */
class CalendarItem {
    var $date;
    var $startTime = "";
    var $endTime = "";
    var $registeredDay = false;
    var $monthType = "this"; //prev next
    
    public static function withDateFormatYYYYMMDD($ydmformat){
        $instance = new self();
        $ydmPattern = "/^([0-9]{4})([0-9]{2})([0-9]{2})$/";
        
        preg_match($ydmPattern, $ydmformat, $matches);
		if(sizeof($matches) == 4){
			$index = $matches[1];
			$instance->date = mktime(0, 0, 0, $matches[2], $matches[3], $matches[1]);
		}
        return $instance;
    }
    
    public static function withDateFormatYYYYMMDDAndType($ydmformat, $type){
        $instance = self::withDateFormatYYYYMMDD($ydmformat);
        $instance->monthType = $type;
        return $instance;
    }
    
	
    
    public function __construct(){
       
    }
    
    public static function withYearMonthDay($year, $month, $day ) {
        $instance = new self();
        $instance->date = mktime(0, 0, 0, $month, $day, $year);
        return $instance;

     
    }
    
    public function toXml() {
        $registered="no";
        if($this->registeredDay)
            $registered="yes";
        return "<calendarItem monthType=\"".$this->monthType."\" date=\"".date("Ymd", $this->date)."\" startTime=\"".$this->startTime."\" endTime=\"".$this->endTime."\" registered=\"".$registered."\"/>";
    }
}

?>
